<template>
  <p-table
    class="table-list-container"
    row-key="id"
    :columns="columns"
    bordered
    :data-source="dataSource"
    :loading="loading"
    v-bind="$attrs"
    v-on="$listeners"
    @change="handleTableChange"
  >
    <a
      :slot="slotName"
      slot-scope="text, record"
      @click="$emit('number-click', record)"
    >
      {{ text }}
    </a>
  </p-table>
</template>

<script>
import { getDicList, postOrganizationInfo } from '@/api/public.js';

export default {
  props: {
    slotName: {
      type: String,
      default: 'product.productNo',
    },
    dataSource: {
      type: Array,
      default: () => [],
    },
    columns: {
      type: Array,
      default: () => [],
    },
    loading: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  computed: {},
  watch: {},

  methods: {
    async postOrganizationInfo() {
      const result = await postOrganizationInfo({
        code: 'ltcsmsizebu',
      });
      const data = result?.data?.data || [];
      return data.reduce((pre, cur) => {
        pre[cur.code] = cur.name;
        return pre;
      }, {});
    },
    async getDicList(code) {
      if (!code) return [];
      const result = await getDicList(code);
      const data = result?.data?.data || [];
      return data.reduce((pre, cur) => {
        pre[cur.value] = cur.label;
        return pre;
      }, {});
    },
    handleTableChange(page, filters, sorter, { currentDataSource }) {
      // console.log(
      //   page,
      //   filters,
      //   sorter,
      //   { currentDataSource },
      //   '0000123========'
      // );
    },
  },
};
</script>

<style lang="less" scoped>
.table-list-container {
  margin-top: 20px;
}
</style>